package com.liveinstars.im.endpoint;

import com.liveinstars.im.core.service.ReportService;
import com.liveinstars.api.im.ReportApi;
import com.liveinstars.api.im.query.ReportQuery;
import com.liveinstars.api.im.vo.ChatGroupMsgReportRecordVO;
import com.liveinstars.api.im.vo.ChatGroupMsgReportVO;
import com.onepiece.shipelves.common.Result;
import com.onepiece.shipelves.common.enums.SystemExceptionEnum;
import com.onepiece.shipelves.common.vo.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: zhouze
 * @date: 2020/3/6
 */
@RestController
public class ReportEndpoint implements ReportApi {

    @Autowired
    private ReportService reportService;

    @Override
    public Result reportChatGroupMsg(@RequestBody ChatGroupMsgReportVO vo) {
        Result result = new Result<>();
        try {
            reportService.reportChatGroupMsg(vo);
        } catch (Exception e) {
            result = SystemExceptionEnum.UN_KNOW_ERROR.createResult();
        }
        return result;
    }

    @Override
    public Result<Page<ChatGroupMsgReportRecordVO>> pageByQuery(@RequestBody ReportQuery query) {
        Result<Page<ChatGroupMsgReportRecordVO>> result = new Result<>();
        try {
            Page<ChatGroupMsgReportRecordVO> page = reportService.pageByQuery(query);
            result.setData(page);
        } catch (Exception e) {
            result = SystemExceptionEnum.UN_KNOW_ERROR.createResult();
        }
        return result;
    }

    @Override
    public Result reportHandle(@RequestParam("id") Long id, @RequestParam("status") Integer status) {
        Result result = new Result<>();
        try {
            reportService.reportHandle(id, status);
        } catch (Exception e) {
            result = SystemExceptionEnum.UN_KNOW_ERROR.createResult();
        }
        return result;
    }
}
